package com.zwl.sjzmanagement.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zwl.model.Tqc;
import com.zwl.model.TqcMaterialsNeed;
import com.zwl.model.TqcUpgrades;
import com.zwl.vo.TqcUpdateNeedsVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TqcMapper  extends BaseMapper<TqcUpdateNeedsVo> {


    @Select("select * from tqc_upgrades where id = #{id}")
    TqcUpgrades queryById(@Param("id") Integer id);

    @Select("select * from tqc")
    List<Tqc> queryTqc();

    @Select("select * from tqc_materials_need where tqc_name=#{tqcName} and level=#{totalLevel} ")
    List<TqcMaterialsNeed> queryTqcMaterialsNeed(@Param("tqcName") String tqcName, @Param("totalLevel") Integer totalLevel);

    @Select("select * from tqc_upgrades where production_location=#{tqcName} and level=#{totalLevel}")
    TqcUpgrades queryTqcUpgrade(@Param("tqcName") String tqcName, @Param("totalLevel") Integer totalLevel);

    @Select("select * from tqc where name = #{productionLocation}")
    Tqc queryTqcByName(@Param("productionLocation") String productionLocation);

    @Update("UPDATE tqc_upgrades " +
            "SET production_location = #{tqcUpgrades.productionLocation}, " +
            "level = #{tqcUpgrades.level}, " +
            "upgrade_prerequisites = #{tqcUpgrades.upgradePrerequisites}, " +
            "required_hafu_coins = #{tqcUpgrades.requiredHafuCoins}, " +
            "total_material_value = #{tqcUpgrades.totalMaterialValue}, " +
            "total_upgrade_cost = #{tqcUpgrades.totalUpgradeCost} " +
            "WHERE id = #{tqcUpgrades.id}")
    void updateTqcUpgrades(@Param("tqcUpgrades") TqcUpgrades tqcUpgrades);

    @Insert("INSERT INTO tqc_upgrades " +
            "(production_location, level, upgrade_prerequisites, required_hafu_coins, " +
            "total_material_value, total_upgrade_cost) " +
            "VALUES " +
            "(#{tqcUpgrades.productionLocation}, #{tqcUpgrades.level}, " +
            "#{tqcUpgrades.upgradePrerequisites}, #{tqcUpgrades.requiredHafuCoins}, " +
            "#{tqcUpgrades.totalMaterialValue}, #{tqcUpgrades.totalUpgradeCost})")
    void addTqcUpgrades(@Param("tqcUpgrades") TqcUpgrades tqcUpgrades);

    @Update("UPDATE tqc_materials_need " +
            "SET tqc_name = #{tqcMaterialsNeed.tqcName}, " +
            "material_name = #{tqcMaterialsNeed.materialName}, " +
            "amount = #{tqcMaterialsNeed.amount}, " +
            "level = #{tqcMaterialsNeed.level} " +
            "WHERE id = #{tqcMaterialsNeed.id}")
    void updateTqcMaterialsNeed(@Param("tqcMaterialsNeed") TqcMaterialsNeed tqcMaterialsNeed);

    @Insert("INSERT INTO tqc_materials_need " +
            "(tqc_name, material_name, amount, level) " +
            "VALUES " +
            "(#{tqcMaterialsNeed.tqcName}, #{tqcMaterialsNeed.materialName}, " +
            "#{tqcMaterialsNeed.amount}, #{tqcMaterialsNeed.level})")
    void addTqcMaterialsNeed(@Param("tqcMaterialsNeed") TqcMaterialsNeed tqcMaterialsNeed);


    @Delete("delete from tqc_upgrades where id=#{id}")
    void deleteTqcUpgradesById(@Param("id") Integer id);

    @Delete("delete from tqc_materials_need where tqc_name=#{tqcName} and level=#{level}")
    void deleteTqcMaterialsNeedByName(@Param("tqcName") String tqcName,@Param("level") Integer level);

    @Update("update tqc set total_level=#{level} where name=#{tqcName}")
    void updateTqc(@Param("tqcName") String tqcName,@Param("level")Integer level);
}
